import time  

fileName = "src/oled.txt"  
buffer = "Hello, World!"  
i = 0  
buffer = buffer.encode("utf-8")  

while i < 100:  
    with open(fileName, "w") as f:  # 使用 with 语句自动管理文件上下文  
        # 将 i 转换为字符串并写入文件  
        f.write(f"1\n")  # 写入当前的 i 值  
        buffer = f"Hello {i}"
        f.write(buffer)  # 将 buffer 解码为字符串并写入 
        f.close()  # 关闭文件
    i += 1
    time.sleep(0.5)
